package com.zjc.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zjc.common.R;
import com.zjc.pojo.Student;
import com.zjc.pojo.SystemAdmin;
import com.zjc.service.SystemAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 周佳成
 * @since 2023-09-17
 */
@RestController
@RequestMapping("/api/sysadmin")
public class SystemAdminController {
	@Autowired
	SystemAdminService systemAdminService;
	@PostMapping("/login")
	public R<SystemAdmin> login(HttpServletRequest httpServletRequest, @RequestBody SystemAdmin sy){
		String password = sy.getPassword();
		LambdaQueryWrapper<SystemAdmin> lambdaQueryWrapper = new LambdaQueryWrapper<>();

		lambdaQueryWrapper.eq(SystemAdmin::getSysId,sy.getSysId());

		SystemAdmin systemAdmin = systemAdminService.getOne(lambdaQueryWrapper);

		if(systemAdmin == null){
			return R.error("用户名不存在!");
		}
		else{
			String pw = systemAdmin.getPassword();
			if(!pw.equals(password)){
				return R.error("密码错误!");
			}
			else{
				httpServletRequest.getSession().setAttribute("user",systemAdmin.getSysId());

				return R.success(systemAdmin);
			}
		}
	}
}

